package SortDemo;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @BelongsProject: LeetCode
 * @BelongsPackage: SortDemo
 * @Author: song
 * @CreateTime: 2023-03-10  01:42
 * @Description: TODO
 * @Version: 1.0
 */

public class showMap {
    public static void main(String[] args) {
        HashMap map = new HashMap<Integer,String>();
        map.put(1,"a");
        map.put(2,"b");
        map.put(3,"c");
        map.put(4,"d");
        System.out.println(map);
        
        // 获取keySet后，foreach遍历
        Set<Integer> keySet = map.keySet();
        for (Integer key : keySet) {
            System.out.print(key+ "="+map.get(key) + "\t");
        }
        System.out.println();
        //获取entrySet后，foreach遍历
        Set<Map.Entry<Integer,String>> entrySet = map.entrySet();
        for (Map.Entry<Integer,String> entry : entrySet){
            System.out.print(entry.getKey() + "=" + entry.getValue() + " ");
        }
        System.out.println();
    }
}
